package top.lingkang.acgv.acr.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor  //无参构造
@AllArgsConstructor //有参构造
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 19951219L;
    private Integer code;
    private String message;
    private T data;
    private long timestamp;

    public long getTimestamp() {
        return System.currentTimeMillis();
    }

    public ResponseResult success(String message) {
        code = 0;
        this.message = message;
        return this;
    }

    public ResponseResult success(T data) {
        code = 0;
        this.data = data;
        return this;
    }

    public ResponseResult success(String message, T data) {
        code = 0;
        this.message = message;
        this.data = data;
        return this;
    }

    public ResponseResult fail(String message) {
        code = 1;
        this.message = message;
        return this;
    }

    public ResponseResult fail(String message, T data) {
        code = 1;
        this.message = message;
        this.data = data;
        return this;
    }

}
